package ar.edu.unq.auxiliar.domain;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import ruleta_wicket.ruleta_wicket.WicketApplication;
import domain.Bet;
import domain.ColumnBet;
import domain.DirectBet;
import domain.OddEvenBet;
import domain.Player;
import domain.RowBet;
import domain.extra.InvalidChipsExeption;

public class BetModel implements Serializable {

	private Player player;
	private List<Bet> bets;
	private Bet bet;
	private Object value;
	private int count;
	
	public BetModel(Player player) {
		this.player = player;
		this.bets = new LinkedList<Bet>();
		addBets();
	}

	private void addBets() {
		this.bets.add(new DirectBet());
		this.bets.add(new ColumnBet());
		this.bets.add(new RowBet());
		this.bets.add(new OddEvenBet());
	}
	
	public void apostar(){
		this.player.makeBet(makeBet(), WicketApplication.getApplication().getTable());
	}

	private Bet makeBet() {
			this.bet.setPlayer(this.player); 
			this.bet.setCount(this.count);
			this.bet.typeOption(this.value); 
		return this.bet;
	}

	public List<String> getBets(){
		List<String> list = new LinkedList<String>();
		for (Bet bet : bets) {
			list.add(bet.getDescription());
		}
		return list;
	}
	
	public List getOptions(String selected){
		obtainBet(selected);
		if(bet == null)
			return new LinkedList();
		return this.bet.getOptions();
	}
	
	private void obtainBet(String name) {
		for (Bet currentBet : bets) {
			if(currentBet.getDescription() == name)
				this.bet = currentBet;
		}
	}

	//public void setTipoApuestas(){}
	//public void setOpcionesAQue(){}

	
	/* *********************************** */ 
	//       Getters and Setters           //
	/* *********************************** */ 
	
	public Player getPlayer() {
		return player;
	}

	public void setPlayer(Player player) {
		this.player = player;
	}

	public Bet getBet() {
		return bet;
	}

	public void setBet(Bet bet) {
		this.bet = bet;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}
}
